package com.jyk.blog.service.impl;

import com.jyk.blog.mapper.TagMapper;
import com.jyk.blog.po.Tag;
import com.jyk.blog.service.BlogTagService;
import com.jyk.blog.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TagServiceImpl implements TagService {
    @Autowired
    TagMapper tagMapper;
    @Autowired
    BlogTagService blogTagService;

    @Override
    public List<Tag> queryAll() {
        return tagMapper.findAll();
    }

    @Override
    public Tag queryById(int id) {
        return tagMapper.findById(id);
    }

    @Override
    public Tag queryByName(String name) {
        return tagMapper.findByName(name);
    }

    @Override
    public void insertOne(String name) {
        tagMapper.insertOne(name);
    }

    @Override
    public void deleteOne(Tag tag) {
        blogTagService.deleteByTag(tag.getNid());
        tagMapper.deleteOne(tag);
    }

    @Override
    public void updateOne(int id, String name) {
        tagMapper.fix(id, name);
    }
}
